//healnpc.txt - Acts like basic npc, but, in addition, this character will sometimes 
//heal a nerby friendly npc.
//Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//Cell 3 - Number of turns between heals.
//Cell 4 - Heal strength. Amount healed is this many d6.
//Cell 5 - Number of sheet with healing animation. Defaults to 2.
//Cell 6 - Number of state when talked to. Plays default text if 0.

begincreaturescript;

variables;

short i,target;
short last_heal;

body;

beginstate INIT_STATE;
	last_heal = get_current_tick();
	break;

beginstate DEAD_STATE;
	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
		inc_flag(get_memory_cell(1),get_memory_cell(2),1);
break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if (my_dist_from_start() >= 6) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}
		else if (get_memory_cell(0) == 0)
			fidget(ME,20);

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	// heal?
	target = get_friendly_target(ME,6,1);
	if ((my_ap() >= 5) && (target > 0) && 
	  (tick_difference(last_heal,get_current_tick()) >= get_memory_cell(3)) && (get_ran(1,0,100) < 90)) {
		if (get_friend_target() == my_number())
			print_named_str(ME,"casts a healing spell.");
			else print_named_str(ME,"heals an ally.");
		if (get_memory_cell(5) == 0)
			run_char_animation(2,1,95);	
			else run_char_animation(get_memory_cell(5),1,95);	
		pc_heard_sound_delay(100,250);						
		last_heal = get_current_tick();
		i = get_ran(get_memory_cell(4),1,12);
		heal_char(get_friend_target(),i);
		run_sparkles_on_char(get_friend_target(),6,8,1);
		deduct_ap(6);
		end();
		}
	
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate TALKING_STATE;
	if (get_memory_cell(6) > 0)
		begin_talk_mode(get_memory_cell(6));
		else print_str("Talking: It doesn't respond.");
break;